import 'package:dio/dio.dart';
import 'package:enterprise_v6_app/app/core/http/http.dart';
import 'package:enterprise_v6_app/app/core/utils/interface.dart';
import 'package:enterprise_v6_app/app/data/entities/auth/weather_entity.dart';

/// 天气信息
class WeatherInfo {
  static WeatherLives? weatherLives;

  // 获取天气数据
  static getWeather() async {
    // final res = await HttpUtil().generateGetRequest<WeatherEntity>(
    //   'https://restapi.amap.com/v3/weather/weatherInfo?city=510108&key=c0cbcaacb9e9b49cb7f6b4f3ae33ba3d'
    // ).execute();

    final res = await Dio().get('https://restapi.amap.com/v3/weather/weatherInfo?city=510108&key=c0cbcaacb9e9b49cb7f6b4f3ae33ba3d');

    if(res.data != null) {
      if(res.data['lives'] != null) {
        if(res.data['lives'] is List) {
          if((res.data['lives'] as List).isNotEmpty) {
            final map = res.data['lives']![0];
            weatherLives = WeatherLives.fromJson(map as Map<String, dynamic>);
          }
        }
      }

    }

    // res.onSuccess((result) {
    //   if (result.data != null && result.data!.lives!.isNotEmpty) {
    //     weatherLives = result.data!.lives![0];
    //   }
    // });
  }
}
